/*
 * @Author: your name
 * @Date: 2021-08-31 09:56:32
 * @LastEditTime: 2021-09-08 08:52:08
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \weplus_weibao\src\store\action.js
 */
import * as types from './mutation-types.js';
import * as api from '../api/server.js';
import { get } from '../api/get.js';
export default {
    getUserEnterPrises ({ commit, state }, payload) {
        try {
            api.getUserEnterprises().then(res => {
                if (res.data.result === 'success') {
                    commit(types.SET_USER_ENTERPRISE, { user_enterprises: res.data.value });
                } else {
                }
            });
        } catch (error) {
            console.log('getUserEnterPrises失败:', error.message);
        }
    },
    getSystemRepairType ({ commit, state }, payload) {
        api.getRepairType({}).then(res => {
            if (res.data.result === 'success') {
                commit(types.SET_SYSTEM_REPAIR_TYPE, res.data.value);
            } else {
                console.log('获取系统数据类型错误', res.data);
            }
        });
    },
    getSystemSolutionMode ({ commit, state }, payload) {
        api.SolutionMode({}).then(res => {
            if (res.data.result === 'success') {
                commit(types.SET_SYSTEM_SOLUTION_MODE, res.data.value);
            } else {
                console.log('获取系统数据类型错误', res.data);
            }
        });
    },
    getSystemServiceMode ({ commit, state }, payload) {
        api.ServiceMode({}).then(res => {
            if (res.data.result === 'success') {
                commit(types.SET_SYSTEM_SERVICE_MODE, res.data.value);
            } else {
                console.log('获取系统数据类型错误', res.data);
            }
        });
    },
    getSystemMessagePreview ({ commit, state }, payload) {
        api.getSystemMessage({
            n: 5,
            p: 1,
            params: '',
            status: '1',
            endtime: '',
            starttime: '',
            msgtype: ''
        }
        ).then(res => {
            if (res.data.result === 'success') {
                commit(types.SYSTEM_MESSGAE_PREVIEW, { messagedata: res.data.value, messagenumber: res.data.number });
            } else {
                console.log('获取系统信息错误', res.data);
            }
        });
    },
    async loadContentConfig ({ commit, state }, url) {
        try {
            const res = await get(url);
            commit(types.SET_CONTENT_CONFIG, res.data);
        } catch (error) {
            console.log(error);
            console.error('加载content config错误', error);
        }
    }

};
